﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;
namespace OracleDAL.Sec
{   
    /// <summary>
    /// 数据访问类SEC_ROLE_TYPE。
    /// </summary>
    public class SEC_ROLE_TYPE
    {
        public SEC_ROLE_TYPE()
        { }
        #region  成员方法

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return OracleHelper.GetMaxID("ROLEID", "SEC_ROLE_TYPE");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ROLEID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from SEC_ROLE_TYPE");
            strSql.Append(" where ROLEID=:ROLEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ROLEID", OracleType.Number,4)};
            parameters[0].Value = ROLEID;
            
            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(Model.Sec.SEC_ROLE_TYPE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SEC_ROLE_TYPE(");
            strSql.Append("ROLEID,ROLENAME,REMARK,SORT)");
            strSql.Append(" values (");
            strSql.Append(":ROLEID,:ROLENAME,:REMARK,:SORT)");
            OracleParameter[] parameters = {
					new OracleParameter(":ROLEID", OracleType.Number,4),
					new OracleParameter(":ROLENAME", OracleType.VarChar,50),
					new OracleParameter(":REMARK", OracleType.VarChar,100),
					new OracleParameter(":SORT", OracleType.Number,4)};
            parameters[0].Value = model.ROLEID;
            parameters[1].Value = model.ROLENAME;
            parameters[2].Value = model.REMARK;
            parameters[3].Value = model.SORT;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(Model.Sec.SEC_ROLE_TYPE model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update SEC_ROLE_TYPE set ");
            strSql.Append("ROLENAME=:ROLENAME,");
            strSql.Append("REMARK=:REMARK,");
            strSql.Append("SORT=:SORT");
            strSql.Append(" where ROLEID=:ROLEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ROLEID", OracleType.Number,4),
					new OracleParameter(":ROLENAME", OracleType.VarChar,50),
					new OracleParameter(":REMARK", OracleType.VarChar,100),
					new OracleParameter(":SORT", OracleType.Number,4)};
            parameters[0].Value = model.ROLEID;
            parameters[1].Value = model.ROLENAME;
            parameters[2].Value = model.REMARK;
            parameters[3].Value = model.SORT;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int ROLEID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete SEC_ROLE_TYPE ");
            strSql.Append(" where ROLEID=:ROLEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ROLEID", OracleType.Number,4)};
            parameters[0].Value = ROLEID;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Sec.SEC_ROLE_TYPE GetModel(int ROLEID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ROLEID,ROLENAME,REMARK,SORT from SEC_ROLE_TYPE ");
            strSql.Append(" where ROLEID=:ROLEID ");
            OracleParameter[] parameters = {
					new OracleParameter(":ROLEID", OracleType.Number,4)};
            parameters[0].Value = ROLEID;

            Model.Sec.SEC_ROLE_TYPE model = new Model.Sec.SEC_ROLE_TYPE();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["ROLEID"].ToString() != "")
                {
                    model.ROLEID = int.Parse(ds.Tables[0].Rows[0]["ROLEID"].ToString());
                }
                model.ROLENAME = ds.Tables[0].Rows[0]["ROLENAME"].ToString();
                model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
                if (ds.Tables[0].Rows[0]["SORT"].ToString() != "")
                {
                    model.SORT = int.Parse(ds.Tables[0].Rows[0]["SORT"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ROLEID,ROLENAME,REMARK,SORT ");
            strSql.Append(" FROM SEC_ROLE_TYPE ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "SEC_ROLE_TYPE";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}
